@extends('layout.admin')
@section('title','修改视频界面')
@section('content')
    <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main" >
        <div class="col-md-12" id="content" >
            <div class="app_content_div" id="app_content_div_301Index">
                <h3>修改视频</h3>
            </div>

            <form class="form-horizontal"  method="post" action="/adm/video-edit/{{$oVideo->id}}">
                <input type="hidden" name="_token" id="_token" value="{{csrf_token()}}" />
                <div class="form-group">
                    <label for="title" class="col-sm-2 control-label"><span style="color:red;">*</span>标题</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="name" name="name" value="{{$oVideo->name}}">
                    </div>
                </div>
                <div class="form-group">
                    <label for="url" class="col-sm-2 control-label"><span style="color:red;">*</span>视频路径</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="video" name="video" value="{{$oVideo->video}}">
                    </div>
                </div>
                <div class="form-group">
                    <label for="type" class="col-sm-2 control-label"><span style="color:red;">*</span>视频类型</label>
                    <div class="col-sm-10">
                        @if($oVideo->type==1)
                            <input type="radio" name="type" id="type" value="0" > 录播
                            <input type="radio" name="type" id="type" value="1" checked> 直播
                        @else
                            <input type="radio" name="type" id="type" value="0" checked> 录播
                            <input type="radio" name="type" id="type" value="1" > 直播
                        @endif
                    </div>
                </div>

                <div class="form-group" >
                    <label for="description" class="col-sm-2 control-label"><span style="color:red;">*</span>课程简介</label>
                    <div class="col-sm-10">
                        <script id="description" name="description" type="text/plain">{{$oVideo->show}}</script>
                        <script type="text/javascript">
                            var editor = UE.getEditor('description')
                        </script>
                    </div>
                </div>
                <div class="form-group">
                    <label for="start_time" class="col-sm-2 control-label"><span style="color:red;">*</span>直播开始时间</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control ui_timepicker" id="start_at" name="start_at" value="{{$oVideo->start_at}}">
                    </div>
                </div>
                <div class="form-group">
                    <label for="end_time" class="col-sm-2 control-label"><span style="color:red;">*</span>直播结束时间</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control ui_timepicker" id="end_at" name="end_at" value="{{$oVideo->end_at}}">
                    </div>
                </div>
                <div class="form-group">
                    <label for="upload_file" class="col-sm-2 control-label"><span style="color:red;">*</span>缩略图</label>
                    <div class="col-sm-10">
                        <input  id="upload_file" name="upload_file"  type="file" onchange="saveThumb()"/>
                        <input type="hidden" class="form-control" id="img_thumb" name="img_thumb" >
                        <img style="width:320px; height:200px;" alt="" id="thumb" src=""  />
                    </div>
                </div>

                <div class="form-group">
                    <label for="expertlist" class="col-sm-2 control-label"><span style="color:red;">*</span>关联专家</label>
                    <div class="col-sm-10">
                        <select id="expert">
                            <option value="">请选择</option>
                            @foreach($oMasters as $o)
                                <option value="7">{{$o->name}}</option>
                            @endforeach
                        </select>
                        <button class="btn btn-default" type="button" onclick="addexpert()">添加</button>
                        <style>
                            .expert{margin:5px;}
                        </style>
                        <div id="expertlist" name="expertlist"></div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        <button type="submit" class="btn btn-default">确定</button>
                    </div>
                </div>
            </form>
        </div>
    </div>

    <script>
        function addexpert(){
            var expert = $('#expert option:selected');
            var flag = true;
            var experthtml = '';
            if(expert.val()){
                $('#expertlist').find('input').each(function(){
                    if($(this).val()==expert.val()){
                        flag = false;
                        return false;
                    }
                });
                if(flag){
                    experthtml += '<div>';
                    experthtml += '		<input type="hidden" value="'+expert.val()+'" name="doc_id[]">';
                    experthtml += '		<span class="expert">'+expert.text()+'</span>';
                    experthtml += '		<span class="glyphicon glyphicon-remove mouse" onclick="$(this).parent().remove()"></span>';
                    experthtml += '</div>';
                    $('#expertlist').append(experthtml);
                }else{
                    alert('您已经添加过该专家了');
                    return false;
                }
            }else{
                alert('请先选择一个专家');
                return false;
            }
        }
    </script>
    <script>
        function saveThumb() {
            $.ajaxFileUpload({
                url: "/adm/video-upload-thumb",
                secureuri: false,
                fileElementId: "upload_file",
                dataType: "json",
                data:{_token:$("#_token").val()},
                success: function(data, status) {
                    if(data.success){
                        $("#img_thumb").val(data.img_thumb);
                        $("#thumb").attr("src", data.img_thumb);
                        alert("添加成功");
                    }else{
                        alert(data.msg);}

                }
            })
        }
    </script>
@endsection
